﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class LINQ
{
    static void Main()
    {
        List<Student> listOfStudents = new List<Student>();
        listOfStudents.Add(new Student("Zarko", "Vidolov", 432392, "0212365", "123@abv.bg", new List<int>() { 3, 4, 5, 2 }, 2,1));
        listOfStudents.Add(new Student("ivan", "Vidolov", 435106, "65878", "65765@abv.bg", new List<int>() { 3, 4, 5 }, 1,1));
        listOfStudents.Add(new Student("Bai", "Mangal", 678687, "02123475475", "fd4564sf@google.com", new List<int>() { 3, 4, 5, 1 }, 2, 1));
        listOfStudents.Add(new Student("Gerogi", "Ivanov", 123606, "002124365", "f123sdfsf@abv.bg", new List<int>() { 3, 4, 5, 6, 2 }, 2, 2));
        listOfStudents.Add(new Student("Dobri", "Mihov", 653205, "199365", "dssbvcf@google.com", new List<int>() { 3, 6, 5, 6, 2 }, 5, 2));
        listOfStudents.Add(new Student("Pe6o", "Kalimanov", 676873, "12365", "123f@yahoo.com", new List<int>() { 3, 2, 4, 5, 6, 2 }, 3, 3));
        listOfStudents.Add(new Student("Min4o", "Kotorov", 354106, "125365", "fdsf@yahoo.com", new List<int>() { 3, 2 }, 5, 4));
        listOfStudents.Add(new Student("ivan", "Vidolov", 145207, "123897-65", "123f@abv.bg", new List<int>() { 3, 4, 5, 6, 2 }, 3, 5));
        listOfStudents.Add(new Student("Go6ko", "Stoqnov", 963202, "12365", "96f@abv.bg", new List<int>() { 3, 4, 5, 6, 2 }, 3, 2));
        listOfStudents.Add(new Student("Petar", "Ivanov", 764006, "14575", "f456@abv.bg", new List<int>() { 3, 4, 5, 6, 2 }, 4, 2));
        listOfStudents.Add(new Student("Petar4o", "Petkov", 643203, "12365", "fd645sf@abv.bg", new List<int>() { 3, 4, 5, 2 }, 4, 1));
        listOfStudents.Add(new Student("Kamen", "6matkov", 653231, "164755", "fdsf@abv.bg", new List<int>() { 3, 2, 6, 5, 2 }, 2, 3));
        listOfStudents.Add(new Student("Andrei", "Ivanov", 864234, "028765", "123gf@google.com", new List<int>() { 3, 4, 5, 6, 2 }, 5, 4));
        listOfStudents.Add(new Student("Glopak", "Typev", 766699, "79365", "123hg@google.com", new List<int>() { 3, 4, 5, 2 }, 1, 4));
        listOfStudents.Add(new Student("Bai", "Ne6toSi", 738998, "0267365", "656ghf@yahoo.com", new List<int>() { 3, 4, 5, 2 }, 1, 2));

        List<Group> listOfGroups = new List<Group>();
        listOfGroups.Add(new Group(1, "Math"));
        listOfGroups.Add(new Group(2, "Bio"));
        listOfGroups.Add(new Group(3, "Info"));
        listOfGroups.Add(new Group(4, "Music"));
        listOfGroups.Add(new Group(5, "English"));

        //var res =
        //    from student in listOfStudents
        //    where student.GNumb == 2
        //    orderby student.FName
        //    select student;
        //foreach (var student in res)
        //{
        //    Console.WriteLine(student);
        //}
        //Console.WriteLine();

        //var stud = listOfStudents.Where(a => a.GNumb == 2).OrderBy(a => a.FName);
        //foreach (var student in stud)
        //{
        //    Console.WriteLine(student);
        //}
        //Console.WriteLine();

        //var res2 =
        //    from student in listOfStudents
        //    where student.Email.EndsWith("@abv.bg")
        //    select student;
        //foreach (var student in res2)
        //{
        //    Console.WriteLine(student);
        //}
        //Console.WriteLine();

        //Regex regx = new Regex(@"\A02");
        //var res3 =
        //    from student in listOfStudents
        //    where regx.IsMatch(student.Tel)
        //    select student;
        //foreach (var student in res3)
        //{
        //    Console.WriteLine(student);
        //}
        //Console.WriteLine();

        //var res4 =
        //    from student in listOfStudents
        //    where student.Marks.Contains(6)
        //    select new { FullName = student.FName + " " + student.LName, Marks = student.Marks};
        //foreach (var student in res4)
        //{
        //    Console.WriteLine(student.FullName);
        //}
        //Console.WriteLine();

        //var res5 =
        //    from student in listOfStudents
        //    where student.Marks.Count(m => m == 2) == 2
        //    select student;
        //foreach (var student in res5)
        //{
        //    Console.WriteLine(student);
        //}
        //Console.WriteLine();

        //var res6 =
        //    from student in listOfStudents
        //    where student.FN.ToString().EndsWith("06")
        //    select student.Marks;
        //foreach (var marks in res6)
        //{
        //    foreach (int mark in marks)
        //    {
        //        Console.Write(mark);
        //    }
        //    Console.WriteLine();
        //}
        //Console.WriteLine();

        //var res7 =
        //    from student in listOfStudents
        //    join gr in listOfGroups on student.Gr equals gr.GNum
        //    where gr.DepName == "Math"
        //    select student;
        //foreach (var student in res7)
        //{
        //    Console.WriteLine(student);
        //}
        //Console.WriteLine();

        //string[] words = { "123", "12345", "1234", "12345678", "123456" };
        //var res8 =
        //    (from word in words
        //     orderby word.Length descending
        //     select word).First();
        //Console.WriteLine(res8);

        var res9 =
            from student in listOfStudents
            join gr in listOfGroups on student.Gr equals gr.GNum
            group student by gr.DepName into g
            select new {g.Key, Values = g}

        foreach (var group in res9)
        {
            Console.WriteLine(group.Key);
            foreach (var st in group.Values)
            {
                Console.WriteLine(st);
            }
            Console.WriteLine();
        }

    }
}

